package com.train.mgr.modules.biz.controller;

import com.train.common.model.PageResult;
import com.train.common.model.R;
import com.train.mgr.modules.biz.dto.request.CourseStuGroupReqDTO;
import com.train.mgr.modules.biz.dto.request.GroupQueryDTO;
import com.train.mgr.modules.biz.dto.response.GroupRespListDTO;
import com.train.mgr.modules.biz.entity.CourseStuGroup;
import com.train.mgr.modules.biz.service.ICourseStuGroupService;
import com.train.mgr.modules.system.dto.request.groups.Insert;
import com.train.mgr.modules.system.dto.request.groups.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 课程学员分组表 前端控制器
 * @author cxg
 * @date 2025-10-02
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@Api( tags = "分组管理[企业端]")
@RequestMapping("/courseStuGroup")
public class CourseStuGroupController {

    private final ICourseStuGroupService courseStuGroupService;

    /**
     * 功能描述:单个获取
     * @author: cxg
     * @date: 2025-10-02
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("查询详情")
    public R<CourseStuGroup> getById(@PathVariable(name = "id") Long id) {
        CourseStuGroup courseStuGroup = courseStuGroupService.getById(id);
        return R.succeed(courseStuGroup);
    }


    /**
     * 条件 分页查询
     * @author: cxg
     * @date: 2025-10-02
     */
    @GetMapping("/page")
    @ApiOperation("分组列表")
    public R<PageResult<GroupRespListDTO>> page(GroupQueryDTO params) {
        return R.succeed(courseStuGroupService.pageList(params));
    }

    /**
	 * 新增
     * @author: cxg
     * @date: 2025-10-02
	 */
    @PostMapping("/add")
    @ApiOperation("新增分组")
    public R<Boolean> add(@RequestBody @Validated(Insert.class) CourseStuGroupReqDTO body) {
        Boolean result = courseStuGroupService.add(body);
        return R.succeed(result);
    }

	/**
	 * 更新
     * @author: cxg
     * @date: 2025-10-02
	 */
    @PostMapping("/update")
    @ApiOperation("更新分组")
    public R<Boolean> update(@RequestBody @Validated(Update.class) CourseStuGroupReqDTO body) {
        Boolean result = courseStuGroupService.update(body);
        return R.succeed(result);
    }

	/**
	 * 删除
     * @author: cxg
     * @date: 2025-10-02
	 */
    @DeleteMapping("/delete")
    @ApiOperation("删除分组")
    public R<Boolean> delete(@RequestParam(name = "id",required = true) Long id) {
          Boolean result = courseStuGroupService.deleteById(id);
          return R.succeed(result);
    }
}
